//#define  _CRT_SECURE_NO_WARNINGS 1  
#include<stdio.h>
#include<stdlib.h>
//typedef int BTDatatype;
//typedef struct BinarytreeNode {
//	BTDatatype data;
//	struct BinarytreeNode* left;
//	struct BinarytreeNode* right;
//}BTNode;

//int BinaryTreeKSize(BTNode* root, int k)
//{
//	if (root == NULL)
//		return 0;
//	if (k == 1)
//		return 1;
//	return BinaryTreeKSize(root->left, k - 1) + BinaryTreeKSize(root->right, k - 1);
//}
//
//BTNode* BinaryTreeFind(BTNode* root, int x)
//{
//	if (root == NULL)
//		return NULL;
//	if (root->data == x)
//		return root;
//	BTNode* p1 = BinaryTreeFind(root->left, x);
//	if (p1)
//		return p1;
//	BTNode* p2 = BinaryTreeFind(root->right, x);
//	if (p2)
//		return p2;
//}
struct TreeNode {
	int val;
	struct TreeNode* left;
	struct TreeNode* right;

};

int BinartTreeSize(struct TreeNode* root)
{
	if (root == NULL)
		return 0;
	return BinartTreeSize(root->left) + BinartTreeSize(root->right) + 1;
}
void preorder(struct TreeNode* root,int* a,int*pi)
{
	if (root == NULL)
		return;
	a[(*pi)++] = root->val;
	preorder(root->left, a, pi);
	preorder(root->right, a, pi);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
	*returnSize = BinartTreeSize(root);
	int* a = (int*)malloc(sizeof(int) * (*returnSize));
    int pi = 0;
	preorder(root, a, &pi);
	return returnSize;
}
